package com.noodles.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.noodles.mall.entity.UserCity;
import com.noodles.mall.mapper.UserCityMapper;
import com.noodles.mall.service.UserCityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserCityServiceImpl extends ServiceImpl<UserCityMapper, UserCity> implements UserCityService {
    /** 增加 **/
    public UserCity insert(UserCity userCity){
        return super.save(userCity)
                ? selectList(userCity.getUserId()).get(0) : null;
    }

    /** 删除 **/
    public boolean delete(Integer id){
        return super.removeById(id);
    }

    /** 修改 **/
    public boolean update(UserCity userCity){
        return super.updateById(userCity);
    }

    /** 查询列表: userId **/
    public List<UserCity> selectList(Integer userId){
        return super.list(new QueryWrapper<UserCity>().lambda()
                .eq(UserCity::getUserId,userId)
                .orderByDesc(UserCity::getCreatedTime)
        );
    }
}
